#ifndef RECVAVPACKET_H
#define RECVAVPACKET_H

#include "mytcpsocket.h"
#include "RingBuffer.h"
#include <QObject>
#include <memory>

extern "C" {
#include <libavcodec/avcodec.h>
}

using std::unique_ptr;
using std::shared_ptr;

class RecvAVPacket : public QObject
{
    Q_OBJECT
public:
    explicit RecvAVPacket(const QString &msg, TaskType stopType, shared_ptr<RingBuffer> pSharedBuffer, QObject *parent = nullptr);
    ~RecvAVPacket();

signals:
    void updateBitRate(double bitRate);
//    void sigTcpDisconnected();

public slots:
    void startRtmp();
    void startPlayback();
    void handleAVPacket(Packet pkt);
    void stop();

private:
    QString _msg; // 请求解码器参数时需要携带的V字段（实时流url或起始终止时间戳+摄像头id+通道号）
    TaskType _stopType; // 通知服务器停止发送AVPacket的T字段（TASK_STOP_RTMP或TASK_STOP_PLAYBACK）
    MyTcpSocket *_pTcpConnection;
    shared_ptr<RingBuffer> _pSharedBuffer;
    bool _isWorking;
};

#endif // RECVAVPACKET_H
